package es.unileon.prg2.censo.composite;

/**
 * @author Manuel Molinos Crespo, Adrian Campazas Vega, Alberto Castro Delgado, Pedro Alvarez Alvarez, Adrian Cabello Galvan, Jose Alvaro Fernandez Alvarez
 *
 */
import org.apache.log4j.Logger;
/**
 * @author Manuel Molinos Crespo
 * @author Adrian Campazas Vega
 * @author Alberto Castro Delgado
 * @author Pedro Alvarez Alvarez
 * @author Adrian Cabello Galvan
 * @author Jose Alvaro Fernandez Alvarez
 *
 */

import java.util.ArrayList;

import es.unileon.prg2.censo.exception.CensoException;
import es.unileon.prg2.censo.handler.DNICitizen;
import es.unileon.prg2.censo.handler.GenericId;
import es.unileon.prg2.censo.handler.Handler;
import es.unileon.prg2.censo.iterator.Iterador;
import es.unileon.prg2.censo.iterator.TreeIterator;

public class Citizen implements Component{
	private static final String LEVEL = "Citizen";
	private Handler id;
	private int age;
	
	/**
	 * Constructor used to created an citizen object. 
	 * @param id Handler with the ID of this Citizen object
	 * @param age Int with the age of this citizen
	 * @throws CensoException
	 */
	public Citizen(Handler id, int age) throws CensoException {
		this(id.toString(), age);
	}
	
	/**
	 * Other constructor used to created an citizen object from a String.
	 * @param id String with the ID of this Citizen object
	 * @param age Int with the age of this citizen
	 * @throws CensoException
	 */
	public Citizen(String id, int age) throws CensoException {
		this.id = new DNICitizen(id);
		this.setAge(age);
	}
	
	@Override
	public String getLevel() {
		return this.LEVEL;
	}

	@Override
	public Component search(Handler id) {	
		if (this.id.compareTo(id) == 0){
			return this;
		}else{
			return null;
		
		}
	}
	
	@Override
	public boolean delete(Component erase) throws CensoException {
		StringBuffer message = new StringBuffer();
		message.append("Citizens can't delete citizen childrens.");
		if(message.length()!= 0){
			throw new CensoException(message.toString());
		}
		return false;
	}

	@Override
	public boolean add(Component creation) throws CensoException{
		StringBuffer message = new StringBuffer();
		message.append("Citizens can't add other levels.");
		if(message.length()!= 0){
			throw new CensoException(message.toString());
		}
		return false;
	}

	@Override
	public int size() {
		return 1;
	}

	@Override
	public Handler getId() {
		return this.id;
	}
	
	@Override
	public String toString() {
		return "\n\t\t\t\t\tCitizen: " + this.getId().toString();
	}

	@Override
	public Composite getComposite() {
		return null;
	}

	public int getAge() {
		return this.age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@Override
	public ArrayList<Component> getChildren() {
		return null;
	}

	@Override
	public Iterador createIterator(int age, int age2) throws CensoException {
		return null;
	}

	@Override
	public Iterador createIterator() throws CensoException {
		return null;
	}
}
